package com.stx.blog.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.stx.blog.service.ArticleService;
import com.stx.blog.util.BlogUtil;
import com.stx.blog.vo.ArticleVo;
import com.stx.blog.vo.BcategoryVo;
import com.stx.blog.vo.UserVo;

public class ArticleAction extends ActionSupport{

	private UserVo uv;
	private BcategoryVo bv;
	private ArticleVo   av;
	private ArticleService as;
	private BlogUtil   bu;
	private List<BcategoryVo> list=new ArrayList<BcategoryVo>();
	private List<ArticleVo> articleList=new ArrayList<ArticleVo>();
	
	public ArticleVo getAv() {
		return av;
	}
	public List<ArticleVo> getArticleList() {
		return articleList;
	}
	public void setArticleList(List<ArticleVo> articleList) {
		this.articleList = articleList;
	}
	public void setAv(ArticleVo av) {
		this.av = av;
	}
	public UserVo getUv() {
		return uv;
	}
	public void setUv(UserVo uv) {
		this.uv = uv;
	}
	public BcategoryVo getBv() {
		return bv;
	}
	public void setBv(BcategoryVo bv) {
		this.bv = bv;
	}
	public ArticleService getAs() {
		return as;
	}
	public void setAs(ArticleService as) {
		this.as = as;
	}
	public BlogUtil getBu() {
		return bu;
	}
	public void setBu(BlogUtil bu) {
		this.bu = bu;
	}
	public List<BcategoryVo> getList() {
		return list;
	}
	public void setList(List<BcategoryVo> list) {
		this.list = list;
	}
	public String showArticle(){
		uv=(UserVo) ServletActionContext.getRequest().getSession().getAttribute("user");
		list=as.findBcategory(uv);
		if(list.size()==0){
			addActionError("请先创建博文分类");
			return "nulllist";
		}
		return "success";
	}
    public String addArticle(){
    	//uv=(UserVo) ServletActionContext.getRequest().getSession().getAttribute("user");
    	 av.setBuid(uv.getBuid());
         av.setCid(bv.getCid());
    	 av.setCreatetime(new Date());
         as.addArticle(av);
         return "addok";
    }
    public String delArticle(){
    	as.delArticle(av);
    	return "delok";
    }
    public String updateArticle(){
    	av.setCreatetime(new Date());
    	 av.setCid(bv.getCid());
    	as.updateArticle(av);
    	return "updateok";
    }
    public String  changeToArticle(){
    	System.out.println(av.getBid());
    	uv=(UserVo) ServletActionContext.getRequest().getSession().getAttribute("user");
		list=as.findBcategory(uv);
		av=as.getArticle(av);
		return "changeto";
    }
    
}
